//
//  UserDefaultsController.swift
//  HHSwift
//
//  Created by 华宏 on 2020/2/15.
//  Copyright © 2020 huahong. All rights reserved.
//

import UIKit

class UserDefaultsController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white
        title = "UserDefaults"
        
        
        
        UserDefaults.standard.register(defaults: ["userName":"张三"])
        let name1 = UserDefaults.standard.string(forKey: "userName")
        print("name1:",name1 ?? "") //张三
        
        UserDefaults.standard.set("李四", forKey: "userName")
//        UserDefaults.standard.synchronize
        let name2 = UserDefaults.standard.object(forKey: "userName")
        print("name2:",name2!) //李四

        UserDefaults.standard.removeObject(forKey: "userName")
        let name3 = UserDefaults.standard.object(forKey: "userName")
        print("name3:",name3!) //张三
    }
    

    
}
